package com.example.designmode.flyweight


/**
 * 享元工厂角色
 * 方块工厂
 *
 * @author zhouronghua
 * @time 2022/3/9 9:14 下午
 */
object BoxFactory {

    var boxMap = HashMap<String, AbstractBox>()

    val default = UnShareBox()

    init {
        boxMap.put("LBox", LBox())
        boxMap.put("IBox", IBox())
        boxMap.put("OBox", OBox())
    }

    /**
     * 获取方块对象
     *
     * @author zhouronghua
     * @time 2022/3/9 9:28 下午
     */
    fun getBox(name: String): AbstractBox {
        return boxMap.getOrDefault(name, default)
    }
}